\section{Compilation Units}

\begin{quote}

\ntermdef{CompilationUnit}

\defspace \keyw{package} \nterm{QualifiedIdentifier} \code{;} \seq{\nterm{Import}} \seq{\nterm{Decl}}

\end{quote}

A compilation unit is made up of a (required) package clause followed
by a sequence of declarations.

\subsection{Imports}

\begin{quote}

\ntermdef{Import}

\defspace \keyw{import} \nterm{QualifiedIdentifier} \opt{\nterm{DotStar}} \code{;}

\ntermdef{DotStar}

\defspace \code{. *}

\end{quote}

An import statement imports a qualified name into the current scope so
it can be referred to by the last identifier in the qualified name.
If the import ends in .*, then all the members of the given \nterm{Name} are
imported into the current scope.

As in Java, importing the same simple name twice is an error unless
the fully qualified name is the same.  Importing a specific simple
name always overrides importing all elements of a package where
that name is defined, regardless of which definition goes first.
In general, Plaid follows the Java Language Specification section
7.5.

\subsection{Java Interoperability}

\minisec{Accessing Java from Plaid.}  Any java package, class, or
class member can be referred to via a qualified name.  Imported
name(s) can include a package, class, or class member from Java.
Instances of a Java class C may be created by invoking C.new(...)  and
passing appropriate arguments for one of the constructors of class C.
A static method m of C may be invoked with the syntax C.m(...).  An
instance methods of a Java object o may be invoked with the syntax
o.m(...).  Arguments passed to calls of Java constructors and methods
may be Java objects.  Plaid integers, strings, and booleans are
converted to appropriate Java primitive, String, and numeric object
types (e.g. java.lang.Integer) depending on the declared type of the
method's formal parameters.  If a Java method takes an Object or
plaid.runtime.PlaidObject as an argument, then a Plaid object can be
passed to it, allowing Java code to access Plaid objects.

\minisec{Implementing Java Interfaces.}  A Plaid state can be declared to
be a case of a Java interface.  In that case, any \keyw{new}
expression that creates an object with that state will generate a
Plaid object that extends the appropriate Java interface.  The Plaid
object may then be passed to a Java method that takes the interface
type as an argument.  Methods of the interface that are invoked by
Java are converted into calls to Plaid methods of the same name and
arguments, as described immediately below.

\minisec{Accessing Plaid from Java.}  Java code may invoke methods of
Plaid objects when those objects implement Java interfaces, as
decribed above, or reflectively through the plaid.runtime.PlaidObject
interface.  When calling a Plaid method through this interface, Java
objects of type Integer, String, Booleans, and other numeric objects
are converted into the corresponding Plaid types.  PlaidObjects and
Java objects are passed through unchanged, and their methods may be
invoked from Plaid in the usual way described above.  The detailed
interface of plaid.runtime.PlaidObject is specified in the javadoc
for that interface.


\subsection{File System Conventions}

A compilation unit is stored in a file with extension .plaid.  For each
top-level declaration in the file, a Java class in the declared package
is created with the name of the top-level declaration.  The Java class
implementing a declaration is found at run time using Java's normal
classpath-based lookup mechanism.

\subsection{Applications}

An application is any globally-visible function that takes no arguments.

\noindent
If the user types at the command line:

\begin{quote}
\cmdline{plaid Name}
\end{quote}

\noindent
where \cmdline{Name} is a qualified name, the \cmdline{plaid}
executable will search the classpath for a declaration of the named
function and will try to execute it.

